#define _CRT_SECURE_NO_WARNINGS 1

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */

class Solution {
public:
    TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNode* target)
    {
        return _getTargetCopy(original, cloned, target);
    }

private:
    TreeNode* _getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNode* target)
    {
        if (original == nullptr) {
            return nullptr;
        }
        else if (original == target) {
            return cloned;
        }

        TreeNode* left = _getTargetCopy(original->left, cloned->left, target);
        if (left != nullptr) {
            return left;
        }

        TreeNode* right = _getTargetCopy(original->right, cloned->right, target);
        if (right != nullptr) {
            return right;
        }

        return nullptr;
    }
};